<!-- 我的绩效-试用期考核 -->
<template>
  <ContentCard>
    <template #header>
      <pageHeaderNew
        :title="title"
        :breadCrumb="breadCrumb"
        show-back
      ></pageHeaderNew>
    </template>
    <ConditionBox :margin-bottom="20">
      <template #left>
        <a-space>
          <a-input-search
            :style="{ width: '220px' }"
            placeholder="考核方案名称"
            search-button
            @search="onSearch"
            @press-enter="onSearch"
            v-model="nameSearch"
          />
        </a-space>
      </template>
      <template #right> </template>
    </ConditionBox>
    <table-turn :table-data="getTableData" ref="tableRef" :args="args">
      <a-table-column :width="60" align="center">
        <template #title> 序号 </template>
        <template #cell="{ rowIndex }">
          {{ rowIndex + 1 }}
        </template>
      </a-table-column>
      <a-table-column
        :width="200"
        data-index="name"
        title="考核名称"
        align="center"
      >
        <template #cell="{ record }">
          {{ record?.name }}
        </template>
      </a-table-column>
      <a-table-column
        :width="80"
        data-index="weight"
        title="权重"
        align="center"
      >
        <template #cell="{ record }"> {{ record.weight }}%</template>
      </a-table-column>
      <a-table-column
        :width="220"
        data-index="cycle"
        title="考核周期"
        align="center"
      >
        <template #cell="{ record }">
          {{ record.cycleStart }} 至 {{ record.cycleEnd }}
        </template>
      </a-table-column>
      <a-table-column
        :width="100"
        data-index="createdBy"
        title="创建人"
        align="center"
      >
        <template #cell="{ record }">
          {{ record.createByUserInfo?.name }}
        </template>
      </a-table-column>
      <a-table-column
        :width="200"
        data-index="createdAt"
        title="创建时间"
        align="center"
      >
        <template #cell="{ record }">
          {{ dayjs(record.createdAt).format('YYYY-MM-DD hh:mm:ss') }}
        </template>
      </a-table-column>
      <a-table-column
        :width="100"
        data-index="optionStatus"
        title="考核状态"
        align="center"
      >
        <template #cell="{ record }">
          {{ getProbationTypeName(record.optionStatus) }}
        </template>
      </a-table-column>
      <a-table-column
        :width="200"
        data-index="definition"
        title="考核结果"
        align="center"
      >
        <template #cell="{ record }">
          {{ getProbationTypeName(record.id) }}
        </template>
      </a-table-column>
      <a-table-column
        :width="100"
        data-index=""
        title="操作"
        fixed="right"
        align="center"
      >
        <template #cell="{ record }">
          <a-button type="text" @click="goEdit(record)">
            {{ getOpraterName(record.optionStatus) }}
          </a-button>
        </template>
      </a-table-column>
    </table-turn>
  </ContentCard>
</template>

<script lang="ts" setup>
import { GetProbationschemeList } from '@/apis/human/base/variationManager/probation/index';
import dayjs from 'dayjs';
import { getProbationExamineStatusName } from '@/utils/utils';

const router = useRouter();
const route = useRoute();
const title = '试用期考核';
const breadCrumb: string[] = ['首页', '我的绩效', '试用期考核'];
let tableRef = ref();
let nameSearch = ref(''); // 搜索框的值
onMounted(() => {
  init();
  refresh();
});

const params = reactive<any>({ id: 0 });
const init = () => {
  params.id = route.query.id ? Number(route.query.id) : void 0;
};
// 表格配置
const args = reactive({
  rowSelection: {
    type: 'checkbox',
    showCheckedAll: true,
    onlyCurrent: false
  }
});
// 获取表格数据
const getTableData = async (pageData?: any) => {
  try {
    if (!params.id) return Promise.resolve({ content: [], pageable: {} });
    const res = await GetProbationschemeList({ ...pageData, id: params.id });
    res.content.reverse();
    return Promise.resolve(res);
  } catch (error: unknown) {
    console.log(error);
  }
};

// 点击搜索框
const onSearch = () => {
  refresh();
};

// 编辑
const goEdit = (record: any) => {
  router.push({
    name: 'MyProbationAssessmentDetail',
    query: { id: record.id }
  });
};

// 刷新表格数据
const refresh = () => {
  tableRef.value.loadData();
};
const arr = [
  '绩效考核方案',
  '试用期考核方案',
  '晋升考核方案',
  '任期考核方案',
  '合同续签考核方案',
  '其他考核方案'
];
const probationTypeArr = [
  '待创建',
  '待提交',
  '待确认',
  '已退回',
  '已生效',
  '变更中',
  '变更中',
  '待自评',
  '待评分',
  '结果待确认',
  '已确认',
  '结果拒绝',
  '结果拒绝',
  '方案不通过',
  '结果申诉',
  '已结束',
  '已结束',
  '申诉超时',
  '已生效',
  '已生效'
];
const geteTypeName = (type: number) => {
  if (!type) return;
  return arr[type - 1];
};
const getProbationTypeName = (type: number) => {
  if (!type) return;
  return probationTypeArr[type - 1];
};
const getBigType = (type: number) => {
  if (type === 1) return '待考核';
  if (type === 2) return '考核中';
  if (type === 3) return '已完成';
  return;
};
const getOpraterName = (type: number) => {
  let str = '查看详情';
  // if (type === 3) {
  //   str = '立即处理';
  // }
  // if (type === 4) {
  //   str = '立即评分';
  // }
  return str;
};
</script>

<style scoped lang="less">
.wrap {
  padding: 20px;

  .header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
  }
}
</style>
